import { LoopFunc } from "../../Types";
import { TILE } from "../../enum";
import { GetRegions } from "./GetRegions";

/** 进行区域划分，清理少于指定数目的区域 */
export const clearRoom: LoopFunc = function (map, MapGenerator) {
    let roomRegions = GetRegions(TILE.Void, map, MapGenerator);

    MapGenerator.roomTiles = roomRegions.filter((wallRegion) => {
        // 当 这个联通区域不够大时，将联通区域抹除, 并且从收集材料中删除
        if (wallRegion.length < MapGenerator.minRoomSize) {
            wallRegion.forEach((tile) => {
                map.set(tile.tileX, tile.tileY, TILE.Wall);
            });
            return false;
        }
        return true;
    });
    return map;
};
